package com.shisfish.domain.generator;

import com.shisfish.domain.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author shisfish
 * @date 2020/1/17
 */
public class TestGenerator {

    private static final int NUMBERS = 10;

    private static List<Test> list = new ArrayList<>();

    static {
        for (int i = 0; i < NUMBERS; i++) {
            Test test = new Test();
            test.setId(i);
            test.setName("name" + i);
            test.setAddress("address" + i);
            test.setAge(18 + i);
            list.add(test);
        }
    }

    public static Test save(Test test) {
        System.out.printf("save %s success", test.toString());
        return test;
    }

    public static Test update(Test test) {
        System.out.printf("update %s success", test.toString());
        return test;
    }

    public static void del(Integer id) {
        System.out.printf("delete id[%d] success", id);
    }

    public static Test findById(Integer id) {
        List<Test> collect = list.stream().filter(t -> t.getId().equals(id)).collect(Collectors.toList());
        if (collect.isEmpty()) {
            System.out.printf("find by id[%d] error. not exists", id);
            return null;
        }
        System.out.printf("find by id[%d] success", id);
        return collect.get(0);
    }

    public static List<Test> findAll() {
        System.out.println("find all success");
        return list;
    }

}
